package Tests;

import Common.Application;
import Common.DataBase;
import Common.TestBase;

import Common.TestManager;
import org.openqa.selenium.By;
import org.testng.annotations.*;
import java.lang.reflect.Method;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertEquals;

/**
 * Commenting test
 */
public class ArticleTest extends TestBase {

    protected static DataBase data = new DataBase();

    @BeforeMethod (groups = {"done","nonstable"})
    public void beforeMethod(final Method method) {
        hb.openBaseUrl();
    }

    @Test(groups = {"done"})
    public void commentPostTest(){
        int s = application.randomizer();
        application.goToArticle4();
        application.commentEdit(data.Message(s));
        hb.sleeper(10000);
        assertTrue(hb.isElementPresent(By.xpath("//*[contains(text(),'" + data.Message(s) + "')]")));
    }

    @Test (groups = {"done"})
    public void commentResetButtonsTest(){
        application.goToArticle4();
        for (int i=0; i<application.commenentTextFields().size(); i++) {
            application.resetButton(application.commenentTextFields(), application.commenentResetButtons(), i);
            assertTrue(application.commenentTextFields().get(i).getText().equals(""));
        }
    }

    @Test (groups = {"done"})//try to reduce comments text area size
    public void commentTextAreaSizeReducing() {
        application.goToArticle4();
        application.reductionCommentsTextAreaSize();
        assertFalse(application.isSizeReduced(application.commenentTextFields()
                .get(application.commenentTextFields().size() - 1)));
    }

    @Test (groups = {"done"}) //try to increase comments text area size
    public void commentTextAreaSizeIncreasing() {
        application.goToArticle4();
        int x=application.increaseCommentsTextAreaSize();
        assertFalse(application.isSizeIncreased(application.commenentTextFields()
                .get(application.commenentTextFields().size() - 1),x,101));
    }

    @Test (groups = {"done"})
    public void articlePlusRate(){
        application.goToArticle4();
        application.votingPlus();
        assertTrue(application.votingAssert());
        hb.refreshPage();
        //assertTrue(application.votingAssert());   Doesn't work, because buttons are active after refreshing page
    }

    @Test (groups = {"done"})
    public void articleMinusRate(){
        application.goToArticle4();
        application.votingMinus();
        assertTrue(application.votingAssert());
        hb.refreshPage();
        //assertTrue(application.votingAssert());   Doesn't work, because buttons are active after refreshing page
    }
}
